package com.powernode.config;

import com.powernode.constant.Constants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class OrderConfig {

    //交换机
    @Bean
    public DirectExchange orderExchange(){
        return new DirectExchange(Constants.EXCHANGE_NAME_ORDER,true,false);
    }

    //队列
    @Bean
    public Queue orderQueue(){
        return new Queue(Constants.QUEUE_NAME_ORDER,true,false,false);
    }

    //绑定
    @Bean
    public Binding orderBinding(Queue orderQueue, DirectExchange orderExchange){
        return BindingBuilder.bind(orderQueue).to(orderExchange).with(Constants.ROUTING_KEY_ORDER);
    }
}
